from logicaltool.BaseTools.file_tools import FileTools


class GetSqlitedFiled(FileTools):
    def __init__(self):
        super().__init__()
        # 智图和新表的对应字典
        self.dicts = {
            "issue": "issue",
            "legal_status": "",
            "page": "begin_page_sort",  # 没找到
            "folio_size": "",
            "province_code": "",
            "subject_clc": "",
            "pagecount": "page_cnt",
            "identifier_pisbn": "",
            "language": "language",
            "provider": "provider",
            "pct_enter_nation_date": "down_date",  # 非法对应
            "identifier_pissn": "issn",
            "if_pdf_fulltext": "",
            "identifier_cnno": "",
            "price": "sub_db_id",  # 无字段 非法对应
            "creator_en": "",
            "cited_cnt": "cited_cnt",
            "provider_id": "product",  # 非法对应
            "country": "country",
            "description_source": "",
            "pct_pub_data": "recv_date",  # 智图无提交时间 先放入这里查看效果
            "title_edition": "",
            "creator_bio": "",
            "contributor": "",
            "volume": "vol",
            "creator_drafting": "",
            "subject_isc": "",
            "applicant": "",
            "jumppage": "",
            "identifier_eisbn": "",
            "if_html_fulltext": "",
            "title_series": "",
            "publisher": "publisher",
            "creator_institution": "",
            "source": "journal_name",
            "lngid": "lngid",
            "identifier_eissn": "eissn",
            "description": "abstracts",
            "description_core": "",
            "subject": "subject_word",
            "description_fund": "",
            "rawid": "rawid",
            "beginpage": "begin_page",
            "subject_csc": "",
            "if_pub1st": "",
            "medium": "",
            "title": "title",
            "provider_subject": "column_info",  # 不确定
            "subject_esc": "",
            "description_unit": "sub_db",  # 非法对应
            "subject_dsa": "",
            "agents": "",
            "creator_discipline": "",
            "description_type": "",
            "subject_en": "keyword",  # 不知道对不对
            "source_en": "",
            "date_impl": "",
            "date_created": "pub_date",
            "provider_url": "provider_url",
            "rawtype": "raw_type",
            "agency": "",
            "title_sub": "",
            "creator_degree": "",
            "title_alternative": "",
            "source_institution": "",
            "description_cycle": "",
            "endpage": "end_page",
            "ref_cnt": "",
            "down_cnt": "",
            "creator_release": "",
            "priority_number": "",
            "cover": "",
            "batch": "batch",
            "type": "source_type",
            "creator": "author",
            "bookid": "",
            "date": "pub_year",
            "pct_app_data": "accept_date",  # 接受日期  智图暂时没有
            "identifier_doi": "doi",
            "description_en": "",
            "identifier_standard": "",
            "gch": "journal_id"
        }

    def deal_sqlite3_select(self, rows):
        for row in rows:
            self.inputobj1.add(row[1])

    def create_sql(self):
        strinsgs = "INSERT INTO modify_title_info_zt("
        for key in self.inputobj1:
            strinsgs += "[{}],".format(key)
        strinsgs += ")"
        print(strinsgs)

    def create_s(self):
        Strings = " VALUES ("
        for key in self.inputobj1:
            Strings += "'%s', "
        Strings += ")"
        print(Strings)

    def create_dicts(self):
        Strings = "self.dicts = {\n"
        for key in self.inputobj1:
            Strings += "\"{}\":\"\",\n".format(key)
        Strings += "}\n"
        print(Strings)

    def create_value(self):
        Strings = "sql = String.format("
        for key in self.inputobj1:
            if not self.dicts[key]:
                velue = "null"
            else:
                velue = self.dicts[key]
            Strings += velue+","
        Strings += ");"
        print(Strings)


if __name__ == "__main__":
    gsf = GetSqlitedFiled()
    gsf.conn_sqlite3(r"./zt_template.db3")
    sql = "PRAGMA table_info(modify_title_info_zt)"
    gsf.set_sql(sql)
    rows = gsf.sqlite_select()
    gsf.deal_sqlite3_select(rows)
    gsf.create_value()
